/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.gad.visualmodule;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import org.gad.model.CompositeStep;
import org.gad.model.ExampleStep;
import org.gad.model.IStepStateListener;
import org.gad.model.SequenceStep;
import org.gad.model.SplitStep;
import org.gad.model.Step;
import org.gad.ui.BoxScene;
import org.gad.ui.SceneFactory;
import org.gad.ui.SceneSupport;
import org.gad.ui.StepWidgetBase;
import org.netbeans.api.visual.action.ActionFactory;
import org.openide.util.NbBundle;

/**
 * Action which shows boxView component.
 */
public class boxViewAction extends AbstractAction
{
    private static BoxScene _scene;
    private static Step _rootStep;
    
    public boxViewAction()
    {
        super(NbBundle.getMessage(boxViewAction.class, "CTL_boxViewAction"));
//        putValue(SMALL_ICON, new ImageIcon(Utilities.loadImage(boxViewTopComponent.ICON_PATH, true)));
    }

    public void actionPerformed(ActionEvent evt)
    {
        boxViewTopComponent win = boxViewTopComponent.findInstance();

        
        
//        _scene = new BoxScene();
//
//        _rootStep = GenerateHugeTree();
//        SplitStep ss = new SplitStep( "Split");
//        ss.AddStep(new ExampleStep("Crossing-over"));
//        (( CompositeStep)_rootStep).AddStep(ss);
//        StepWidgetBase swb = new SceneFactory().CreateWidgets(_scene, _rootStep );
//        _scene.getMainLayer().addChild(swb);
//        
//        _scene.getActions().addAction(ActionFactory.createZoomAction());
//        _scene.getActions().addAction(ActionFactory.createPanAction());
//
//        
//        _rootStep.setStepChangeListener(new IStepStateListener( ) {
//            
//            public void StepStateChanged(Step step)
//            {
//                regenerateScene( _scene );
//            }
//
//
//        });
//        
//        win.setPanel(_scene.createView());
        
                win.open();
        win.requestActive();
        
    }
    
    private static void regenerateScene(BoxScene scene)
    {
        scene.clear();
        StepWidgetBase swb = new SceneFactory().CreateWidgets(scene, _rootStep );
        _scene.getMainLayer().addChild(swb);
    }
    
    public static CompositeStep GenerateSeq()
    {
        SequenceStep result = new SequenceStep( "Sequence1");
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Mutation"));
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Inversion"));
        result.AddStep(new ExampleStep( "Mutation"));
        result.AddStep(new ExampleStep( "Crossing-over"));
        return result;
    }

    public static CompositeStep GenerateSplit()
    {
        SplitStep result = new SplitStep( "Split1");
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Mutation"));
        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(new ExampleStep( "Inversion"));
        return result;
    }

    public static CompositeStep GenerateBigTree()
    {
        SequenceStep result = new SequenceStep("Sequence2");

        result.AddStep(GenerateSplit());
        result.AddStep(GenerateSplit());

        result.AddStep(new ExampleStep( "Crossing-over"));

        result.AddStep(new ExampleStep( "Crossing-over"));
        result.AddStep(GenerateSplit());
        result.AddStep(GenerateSplit());
        return result;
    }

    public static CompositeStep GenerateHugeTree()
    {
        SplitStep result = new SplitStep( "Split2");
        result.AddStep(GenerateBigTree());
        result.AddStep(GenerateSeq(  ));

        result.AddStep(GenerateBigTree());
        return result;
    }
}
